package com.example.controller.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.common.Result;
import com.example.dto.ArticlePageDTO;
import com.example.service.ArticleService;
import com.example.service.TagService;
import com.example.vo.ArticlePageVO;
import com.example.vo.TagVO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController("webTagController")
@RequestMapping("/tag")
public class TagController {

    @Resource
    private TagService tagService;
    
    @Resource
    private ArticleService articleService;

    @PostMapping("/list")
    public Result<List<TagVO>> list() {
        List<TagVO> list = tagService.getTagList();
        return Result.success(list);
    }
    
    @PostMapping("/article/list")
    public Result<IPage<ArticlePageVO>> articleList(@RequestBody ArticlePageDTO articlePageDTO) {
        log.info("获取标签文章列表 - 标签ID: {}, 页码: {}, 每页数量: {}", 
                articlePageDTO.getTagId(), 
                articlePageDTO.getCurrent(),
                articlePageDTO.getSize());
                
        IPage<ArticlePageVO> pageResult = articleService.getTagArticles(articlePageDTO);
        
        log.info("标签文章列表响应 - 标签ID: {}, 总记录数: {}, 总页数: {}", 
                articlePageDTO.getTagId(), 
                pageResult.getTotal(),
                pageResult.getPages());
                
        return Result.success(pageResult);
    }
} 